package net.cctms.zhishu.webAppFramework.utils;

import android.content.Context;
import android.os.Environment;

import java.io.File;

/**
 * 存储工具类
 */
public final class StorageUtil {


    public static  final String mRootDirName = "zhishu";
    public static  final String mTempRootDirName = Environment.getExternalStorageDirectory()+File.separator+ mRootDirName+ File.separator+ Constants.HOTFIX;
    public static  final String mOldRootDirName = "BreakingNews";

	private static File mRootDir = null;
	private static Context mAppCtx = null;



    public static  boolean init(Context appCtx) {
        mAppCtx = appCtx;
    	if(mRootDir == null) {
            mRootDir = new File( Environment.getExternalStorageDirectory(), mRootDirName);
    	}
		return true;
	}

    public static String getAppFilePath(Context context){
        File cacheDir = context.getFilesDir();//文件所在目录为getFilesDir();
        String cachePath= cacheDir.getPath();
        return cachePath;
    }


    public static  File getRootDir() {
		return mRootDir;
	}

    /**
     * 获取老头版的文件夹目录
     * @return
     */
    public static File getOldRootDir(){

        return new File( Environment.getExternalStorageDirectory(), mOldRootDirName);
    }

    /**
     * 获取存储APK的目录
     * @return
     */
    public static  File getApkDir() {
        File apkDir =new File(getRootDir(), "apk");
        if(!apkDir.exists()){
            apkDir.mkdirs();
        }
        return apkDir;
    }

    /**
     * 获取图片的缓存目录
     * @return
     */
    public static  File getImageDir() {
        File imageDir =new File(getRootDir(), "image");
        if(!imageDir.exists()){
            imageDir.mkdirs();
        }
        return imageDir;
    }

    /**
     * 获取下载图片的保存目录
     * @return
     */
    public static File getDownloadImageDir(){
        File mPictrueBrowseDir = new File(getRootDir(), "kanjian_img");
        if(!mPictrueBrowseDir.exists()){
            mPictrueBrowseDir.mkdirs();
        }
        return mPictrueBrowseDir;
    }

    /**
     * 获取文章的缓存目录
     * @return
     */
    public static  File getArticleDir() {
        File imageDir =new File(getRootDir(), "Article");
        if(!imageDir.exists()){
            imageDir.mkdirs();
        }
        return imageDir;
    }


}
